package com.anyou.mall.goo.specs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.annotation.ShopScope;
import com.anyou.mall.goo.specs.Param.addSpecsParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.goo.specs.domain.SpeSpecs;
import com.anyou.mall.goo.specs.service.ISpeSpecsService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 规格管理Controller
 *
 * @author ruoyi
 * @date 2022-03-25
 */
@Api(tags = "规格管理")
@RestController
@RequestMapping("/specsList/specs")
public class SpeSpecsController extends BaseController
{
    @Autowired
    private ISpeSpecsService speSpecsService;

    /**
     * 查询规格管理列表
     */
    @ApiOperation("查询规格管理列表")
    @PreAuthorize("@ss.hasPermi('specsList:specs:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<SpeSpecs>> list(SpeSpecs speSpecs)
    {
        startPage();
        return getDataTable(speSpecsService.selectSpeSpecsList(speSpecs));
    }

    /**
     * 导出规格管理列表
     */
    @ApiOperation("导出规格管理列表")
    @PreAuthorize("@ss.hasPermi('specsList:specs:export')")
    @Log(title = "规格管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias="a")
    public void export(SpeSpecs speSpecs,HttpServletResponse response )
    {
        List<SpeSpecs> list = speSpecsService.selectSpeSpecsList(speSpecs);
        ExcelUtil<SpeSpecs> util = new ExcelUtil<SpeSpecs>(SpeSpecs.class);
        util.exportExcel(response, list, "规格管理数据");
    }

    /**
     * 获取规格管理详细信息
     */
    @ApiOperation("获取规格管理详细信息")
    @PreAuthorize("@ss.hasPermi('specsList:specs:query')")
    @GetMapping(value = "/{specsId}")
    public ApiResult<SpeSpecs> getInfo(@PathVariable("specsId") Long specsId)
    {
        return ApiResult.success(speSpecsService.selectSpeSpecsBySpecsId(specsId));
    }

    /**
     * 新增规格管理
     */
/*    @ApiOperation("新增规格管理")
    @PreAuthorize("@ss.hasPermi('specsList:specs:add')")
    @Log(title = "规格管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody SpeSpecs speSpecs)
    {
        return ApiResult.success(speSpecsService.insertSpeSpecs(speSpecs));
    }*/

    /**
     * 修改规格管理
     */
    @ApiOperation("修改规格管理")
    @PreAuthorize("@ss.hasPermi('specsList:specs:edit')")
    @Log(title = "规格管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody SpeSpecs speSpecs)
    {
        return ApiResult.success(speSpecsService.updateSpeSpecs(speSpecs));
    }

    /**
     * 删除规格管理
     */
/*    @ApiOperation("批量删除规格管理")
    @PreAuthorize("@ss.hasPermi('specsList:specs:remove')")
    @Log(title = "规格管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{specsIds}")
    public ApiResult remove(@PathVariable Long[] specsIds)
    {
        return ApiResult.success(speSpecsService.deleteSpeSpecsBySpecsIds(specsIds));
    }*/
    @ApiOperation("删除规格管理")
    @PreAuthorize("@ss.hasPermi('specsList:specs:remove')")
    @Log(title = "规格管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{specsIds}")
    public ApiResult remove(@PathVariable Long specsIds)
    {
        return ApiResult.success(speSpecsService.deleteSpeSpecsBySpecsId(specsIds));
    }


    /**
     * 新增/修改商品规规格 规格值
     */
    @ApiOperation("新增/规格 规格值")
    @PreAuthorize("@ss.hasPermi('specsList:specs:add')")
    @Log(title = "规格 规格值", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addGoodsSpecs")
    public ApiResult insertSpecs(@RequestBody addSpecsParam addSpecsParam)
    {
        return ApiResult.success(speSpecsService.insertSpecs(addSpecsParam));
    }


    @ApiOperation("根据汽配商ID查询规格")
    @GetMapping("/getListByShopId")
    public ApiResult<List<SpeSpecs>> getListByShopId(@RequestParam Long carPartsShopId){

        return speSpecsService.getListByShopId(carPartsShopId);
    }
}
